package com.team.ssm_item_lj.service.impl;

import com.team.ssm_item_lj.entity.ActivityLogs;
import com.team.ssm_item_lj.dao.ActivityLogsDao;
import com.team.ssm_item_lj.service.ActivityLogsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;

/**
 * 活动记录表(ActivityLogs)表服务实现类
 *
 * @author zhuxhenxin
 * @since 2024-12-05 10:44:29
 */
@Service("activityLogsService")
public class ActivityLogsServiceImpl implements ActivityLogsService {
    @Resource
    private ActivityLogsDao activityLogsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ActivityLogs queryById(Integer id) {
        return this.activityLogsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param activityLogs 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActivityLogs> queryByPage(ActivityLogs activityLogs, PageRequest pageRequest) {
        long total = this.activityLogsDao.count(activityLogs);
        return new PageImpl<>(this.activityLogsDao.queryAllByLimit(activityLogs, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param activityLogs 实例对象
     * @return 实例对象
     */
    @Override
    public ActivityLogs insert(ActivityLogs activityLogs) {
        this.activityLogsDao.insert(activityLogs);
        return activityLogs;
    }

    /**
     * 修改数据
     *
     * @param activityLogs 实例对象
     * @return 实例对象
     */
    @Override
    public ActivityLogs update(ActivityLogs activityLogs) {
        this.activityLogsDao.update(activityLogs);
        return this.queryById(activityLogs.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.activityLogsDao.deleteById(id) > 0;
    }
}
